﻿using System;
using System.IO;
using System.Collections.Generic;


class WordCount
{
    static void Main()
    {
        StreamReader readFirstFile = new StreamReader("words.txt");
        StreamReader readSecondFile = new StreamReader("test.txt");
        StreamWriter writeResult = new StreamWriter("result.txt");
        string[] arrOfStrings = readFirstFile.ReadToEnd().Split(' ');
        string[] arrayOfStr = readSecondFile.ReadToEnd().Split(' ');
        using (readFirstFile)
        {
            Console.WriteLine("THE FIRST FILE IS:");
            for (int index = 0; index < arrOfStrings.Length; index++)
            {
                Console.WriteLine(arrOfStrings[index]);
            }
        }
        Console.WriteLine();
        using (readSecondFile)
        {
            Console.WriteLine("THE SECOND FILE IS:");
            for (int index = 0; index < arrayOfStr.Length; index++)
            {
                Console.WriteLine(arrayOfStr[index]);
            }
        }
        using(writeResult)
        {
            for (int index = 0; index < arrOfStrings.Length; index++)
            {
                int counter = 0;
                for (int i = 0; i < arrayOfStr.Length; i++)
                {
                    if (arrOfStrings[index] == arrayOfStr[i])
                    {
                        counter++;
                        arrayOfStr[i] = "";
                    }
                }
                writeResult.WriteLine("{0}: {1} times", arrOfStrings[index], counter);
            }
        }
    }
}

